Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

%read in chunks for lseek()able files. #107

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

jpco
Copy link
Collaborator

@jpco jpco commented Aug 15, 2024

This is a performance optimization that's normally insignificant; occasionally good, in tight %read loops; and very rarely negative, when those tight %read loops work on a file with mostly zero-to-one character lines. Generally the performance improvement increases as line lengths increase, which shouldn't be a surprise. Files with pretty short lines, like /usr/share/dict/words, see a measurable improvement with tight %read loops, though.

In theory, it seems to me the overhead of the extra lseek() calls (which are the source of the negative effects, where they appear) could be reduced by caching the seekability of fds. Maybe just one such value, assuming performance-sensitive calls to %read are typically done repeatedly in a loop (and on a single fd).

This introduces an awkward performance asymmetry, sadly, between the cases of cat foo | the_script and the_script < foo , since stdin in the former case is non-seekable from a pipe, while in the latter case it's seekable.

I'm not married to this proposal. Just wanted to put it out there. I'm not very good at speedy code so there's very possibly a better way to do this than I've got here :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant